﻿using PRO.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using PRO.Common;
using System.Web.UI.HtmlControls;
using PRO.Config;
using System.Web.UI;
using System.Reflection;

namespace PRO.User
{
    public class PageBase : System.Web.UI.Page
    {
        public HtmlMeta keyworks = new HtmlMeta();
        public HtmlMeta description = new HtmlMeta();
        protected CookieInfo UserInfo = UserLib.GetUserInfo();
        
        protected override void OnLoad(EventArgs e)
        {
            if (this.Master != null)
            {
                HtmlMeta meta = null;
                for (int i = 0; i < this.Master.Page.Header.Controls.Count; i++)
                {
                    meta = this.Master.Page.Header.Controls[i] as HtmlMeta;
                    if (meta != null)
                    {
                        if (meta.Name.Equals("keywords"))
                        {
                            keyworks = meta;
                            keyworks.Content = BaseConfigs.Keywords;
                        }
                        else if (meta.Name.Equals("description"))
                        {
                            description = meta;
                            description.Content = BaseConfigs.Description;
                        }
                    }
                }

                Literal Literal_UserInfo = (Literal)this.Master.FindControl("Literal_UserInfo");
                if (Literal_UserInfo != null)
                {
                    if (UserInfo != null && UserInfo.ID > 0 && !UserInfo.Nick.IsNullOrWhiteSpace() && !UserInfo.UserName.IsNullOrWhiteSpace() && !UserInfo.Pwd.IsNullOrWhiteSpace())
                        Literal_UserInfo.Text = string.Format("<a href=\"/member\">"+UserInfo.Nick + "</a> 欢迎登陆！    <a href=\"/logout?url={0}\">退出</a>", Request.RawUrl.UrlEncode());
                    else
                        Literal_UserInfo.Text = string.Format("<a href=\"/login?url={0}\">登陆</a>  |  <a href=\"/register?url={0}\">注册</a>", (CVGRequest.GetQueryString("url").IsNullOrWhiteSpace()) ? Request.RawUrl.UrlEncode() : CVGRequest.GetQueryString("url").UrlEncode());
                }
            }
            this.Title = BaseConfigs.Title;
            base.OnLoad(e);
        }
    }
}
